layui.config({
	base : "js/"
}).use(['form','layer','jquery','layedit','laydate'],function(){
	var form = layui.form(),
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		$ = layui.jquery;

	form.on("switch(Status)",function(data){
		if(data.elem.checked){
			$('input[name=status]').val('1');
		}else{
			$('input[name=status]').val('0');
		}
	})
    form.on("submit(addAdmin)",function(data){
		var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
    	$.ajax({
			type:'post',
			url:'/admin/admin/store',
            async:false,
			data:{
			 	_token:$('input[name=_token]').val(),
				account:$('input[name=account]').val(),
				name:$('input[name=name]').val(),
				phone:$('input[name=phone]').val(),
				pwd:$('input[name=pwd]').val(),
				role_id:$('select[name=role] option:selected').val(),
				status:$('input[name=status]').val()
			},
			dateType:'html',
			success:function (data) {
			 	if(data == 1){
                    top.layer.close(index);
                    // top.layer.msg(data);
                    top.layer.msg("账号添加成功！");
                    layer.closeAll("iframe");
    //                 //刷新父页面
                    parent.location.reload();
				}else{
                    top.layer.close(index);
                    top.layer.msg("账号添加失败！");
				}
            }
		});
        return false;
	})
})
